package com.gzk.basic.service.impl;

import com.gzk.basic.mapper.BaseMapper;
import com.gzk.basic.query.BaseQuery;
import com.gzk.basic.service.IBaseService;
import com.gzk.basic.util.PageList;
import com.gzk.org.domain.Department;
import com.gzk.system.MyLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;


    @Override
    @Transactional
    @MyLog(description = "保存一条数据")
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    @Transactional
    @MyLog(description = "修改一条数据")
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    @MyLog(description = "根据id删除数据")
    public void remove(Long id) {
        mapper.delete(id);
    }

    @Override
    @MyLog(description = "根据id查询数据")
    public T queryById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    @MyLog(description = "查询所有数据")
    public List<T> queryAll() {
        return mapper.loadAll();
    }

    @Override
    @MyLog(description = "分页查询")
    public PageList<T> queryPage(BaseQuery query) {
        //条件查询总数
        Long totals = mapper.queryCount(query);

        //条件查询数据
        List<T> rows = mapper.queryData(query);
        return new PageList<T>(totals,rows);
    }

    @Override
    @Transactional
    @MyLog(description = "批量删除数据")
    public void removeMany(List<Long> ids) {
        mapper.deleteMany(ids);
    }
}
